home *** CD-ROM | disk | FTP | other *** search
/ Champak 128 / Vol 128 (Damaged).iso / games / macera.swf / scripts / frame_155 / DoAction.as
Encoding:
Text File  |  2011-03-26  |  6.8 KB  |  306 lines

  1. stop();
  2. showtime = 60;
  3. points = 0;
  4. exit = "yes";
  5. showcoins = "no";
  6. moveLayer.hero.gotoAndStop(1);
  7. levelcomplete._visible = false;
  8. var onground = false;
  9. jumpsetup = false;
  10. countdown = function()
  11. {
  12.    currtime = getTimer() / 1000;
  13.    minustime = Math.floor(currtime - starttime);
  14.    timeleft = Math.floor(limittime - minustime);
  15.    showtime = timeleft;
  16.    if(_root.timeleft <= 0)
  17.    {
  18.       _root.gotoAndStop("lose");
  19.    }
  20. };
  21. moveme = function()
  22. {
  23.    var _loc1_ = this;
  24.    if(_loc1_.x == undefined)
  25.    {
  26.       _loc1_.startx = _loc1_.x = _loc1_._x;
  27.       _loc1_.starty = _loc1_.y = _loc1_._y;
  28.    }
  29.    _loc1_.dy += 0.5;
  30.    var nexty = Math.ceil(_loc1_.y + _loc1_.dy);
  31.    var nextx = _loc1_.x + _loc1_.dx;
  32.    onground = false;
  33.    if(_loc1_.dy >= 0)
  34.    {
  35.       if(moveLayer.platforms.hitTest(_loc1_.x + moveLayer._x,nexty + moveLayer._y,true) && !jumpsetup)
  36.       {
  37.          onground = true;
  38.          jumping = false;
  39.          var _loc3_ = 0;
  40.          var _loc2_ = Math.floor(nexty);
  41.          while(moveLayer.platforms.hitTest(_loc1_.x + moveLayer._x,_loc2_ + moveLayer._y,true))
  42.          {
  43.             _loc3_ = _loc3_ + 1;
  44.             _loc2_ -= 2;
  45.          }
  46.          if(_loc3_ < 10)
  47.          {
  48.             _loc1_.y = _loc2_;
  49.             _loc1_.dy = 0;
  50.          }
  51.          else
  52.          {
  53.             _loc1_.x -= _loc1_.dx;
  54.             _loc1_.dx = 0;
  55.          }
  56.       }
  57.       else if(_loc1_.dy > 5 && !shooting)
  58.       {
  59.          _loc1_.gotoAndStop(3);
  60.          _loc1_.mc.gotoAndStop(11);
  61.       }
  62.    }
  63.    else if(_loc1_.dy < 0)
  64.    {
  65.       if(moveLayer.platforms.hitTest(_loc1_.x + moveLayer._x,nexty + moveLayer._y - 40,true))
  66.       {
  67.          _loc1_.dy = 1;
  68.       }
  69.    }
  70.    if(moveLayer.exit.hitTest(_loc1_.x + moveLayer._x,_loc1_.y + moveLayer._y - 40,true))
  71.    {
  72.       _root.gotoAndStop("win");
  73.    }
  74.    if(_loc1_.dy > 9)
  75.    {
  76.       _loc1_.dy = 9;
  77.    }
  78.    if(!jumpsetup)
  79.    {
  80.       _loc1_.x += _loc1_.dx;
  81.       _loc1_.y += _loc1_.dy;
  82.    }
  83.    if(Key.isDown(39) && !shooting)
  84.    {
  85.       if(jumping)
  86.       {
  87.          _loc1_.dx += 0.4;
  88.       }
  89.       else
  90.       {
  91.          _loc1_.dx += 1;
  92.       }
  93.       _loc1_._xscale = 80;
  94.    }
  95.    else if(Key.isDown(37) && !shooting)
  96.    {
  97.       if(jumping)
  98.       {
  99.          _loc1_.dx -= 0.4;
  100.       }
  101.       else
  102.       {
  103.          _loc1_.dx -= 1;
  104.       }
  105.       _loc1_._xscale = -80;
  106.    }
  107.    else
  108.    {
  109.       _loc1_.dx *= 0.7;
  110.    }
  111.    if(_loc1_.dx > 7)
  112.    {
  113.       _loc1_.dx = 7;
  114.    }
  115.    if(_loc1_.dx < -7)
  116.    {
  117.       _loc1_.dx = -7;
  118.    }
  119.    if(!jumpsetup && !jumping && !shooting && onground)
  120.    {
  121.       if(Math.abs(_loc1_.dx) < 0.5)
  122.       {
  123.          _loc1_.dx = 0;
  124.          _loc1_.gotoAndStop(1);
  125.       }
  126.       else
  127.       {
  128.          _loc1_.gotoAndStop(2);
  129.       }
  130.    }
  131.    if(Key.isDown(38) && _loc1_.dy >= 0 && _loc1_.dy < 1 && !jumping)
  132.    {
  133.       onground = false;
  134.       shooting = false;
  135.       jumping = true;
  136.       jumpsetup = true;
  137.       _loc1_.gotoAndStop(3);
  138.    }
  139.    lasty = _loc1_._y;
  140.    moveLayer._x = Math.round(160 - _loc1_.x);
  141.    moveLayer._y = Math.round(150 - _loc1_.y);
  142.    if(moveLayer._y < -1268)
  143.    {
  144.       moveLayer._y = -1268;
  145.    }
  146.    bg._x = moveLayer._x / 2 - 160;
  147.    bg._y = moveLayer._y / 2 - 120;
  148.    if(Key.isDown(32) && !shooting)
  149.    {
  150.       shooting = true;
  151.       jumping = false;
  152.       jumpsetup = false;
  153.       _loc1_.gotoAndStop(4);
  154.    }
  155.    if(_loc1_.y > 1580)
  156.    {
  157.       _loc1_.x = _loc1_.startx;
  158.       _loc1_.y = _loc1_.starty;
  159.       _root.gotoAndStop("lose");
  160.    }
  161.    _loc1_._x = Math.floor(_loc1_.x);
  162.    _loc1_._y = Math.floor(_loc1_.y);
  163. };
  164. moveBullet = function()
  165. {
  166.    var _loc1_ = this;
  167.    _loc1_._x += _loc1_.dx;
  168.    if(_loc1_._x < moveLayer.hero._x - 170 || _loc1_._x > moveLayer.hero._x + 170)
  169.    {
  170.       _loc1_.removeMovieClip();
  171.    }
  172. };
  173. createBullet = function()
  174. {
  175.    var _loc1_ = moveLayer.hero._xscale / 80;
  176.    nm = "bul0";
  177.    moveLayer.attachMovie("bullet",nm,100);
  178.    moveLayer[nm]._x = moveLayer.hero._x + 35 * _loc1_;
  179.    moveLayer[nm]._y = moveLayer.hero._y - 25;
  180.    moveLayer[nm]._xscale = _loc1_ * 100;
  181.    moveLayer[nm].dx = 20 * _loc1_;
  182.    moveLayer[nm].onEnterFrame = moveBullet;
  183. };
  184. moveSplat = function()
  185. {
  186.    var _loc1_ = this;
  187.    _loc1_._x += _loc1_.dx;
  188.    if(_loc1_._x < moveLayer.hero._x - 300 || _loc1_._x > moveLayer.hero._x + 300)
  189.    {
  190.       _loc1_.removeMovieClip();
  191.    }
  192.    if(_loc1_.hitTest(moveLayer.hero))
  193.    {
  194.       moveLayer.hero.dx = _loc1_.dx * 5;
  195.       moveLayer.hero.dy = -2;
  196.       _loc1_.removeMovieClip();
  197.    }
  198. };
  199. numsplats = 0;
  200. createSplat = function()
  201. {
  202.    var _loc2_ = this;
  203.    var _loc1_ = _loc2_._xscale / 80;
  204.    nm = "splat" add numsplats;
  205.    moveLayer.attachMovie("splatBullet",nm,numsplats + 200);
  206.    moveLayer[nm]._x = _loc2_._x + 35 * _loc1_;
  207.    moveLayer[nm]._y = _loc2_._y - 25;
  208.    moveLayer[nm]._xscale = _loc1_ * 100;
  209.    moveLayer[nm].dx = 10 * _loc1_;
  210.    moveLayer[nm].onEnterFrame = moveSplat;
  211.    numsplats++;
  212.    numsplats %= 20;
  213. };
  214. simpleMove = function()
  215. {
  216.    var _loc1_ = this;
  217.    if(_loc1_.x == undefined)
  218.    {
  219.       _loc1_.x = _loc1_._x;
  220.       _loc1_.y = _loc1_._y;
  221.    }
  222.    _loc1_.x += _loc1_.dx;
  223.    _loc1_.y += _loc1_.dy;
  224.    if(_loc1_.x < _loc1_.x1)
  225.    {
  226.       _loc1_.x = _loc1_.x1;
  227.       _loc1_.dx *= -1;
  228.    }
  229.    else if(_loc1_.x > _loc1_.x2)
  230.    {
  231.       _loc1_.x = _loc1_.x2;
  232.       _loc1_.dx *= -1;
  233.    }
  234.    if(_loc1_.dx > 0)
  235.    {
  236.       _loc1_._xscale = 80;
  237.    }
  238.    else if(_loc1_.dx < 0)
  239.    {
  240.       _loc1_._xscale = -80;
  241.    }
  242.    _loc1_._x = Math.floor(_loc1_.x);
  243.    _loc1_._y = Math.floor(_loc1_.y);
  244.    if(_loc1_.hitTest(moveLayer.hero))
  245.    {
  246.       moveLayer.hero.dx = _loc1_.dx * 5;
  247.       moveLayer.hero.dy = -2;
  248.    }
  249.    if(_loc1_.hitTest(moveLayer.bul0))
  250.    {
  251.       _loc1_.gotoAndStop(2);
  252.       _root.points = _root.points + 1;
  253.       _loc1_.onEnterFrame = null;
  254.    }
  255.    if(random(100) == 0)
  256.    {
  257.       _loc1_.gotoAndStop(3);
  258.    }
  259. };
  260. coinfunc = function()
  261. {
  262.    var _loc1_ = this;
  263.    if(_root.showcoins == "yes")
  264.    {
  265.       _loc1_.gotoAndStop(1);
  266.    }
  267.    if(_loc1_.hitTest(moveLayer.hero))
  268.    {
  269.       _loc1_.gotoAndStop(2);
  270.       _root.points = _root.points + 1;
  271.    }
  272. };
  273. intro.playButton.onRelease = function()
  274. {
  275.    var _loc1_ = _root;
  276.    intro._visible = false;
  277.    trace(_loc1_.showcoins);
  278.    _loc1_.showcoins = "no";
  279.    starttime = getTimer() / 1000;
  280.    limittime = 60;
  281.    points = 0;
  282.    _loc1_.exit = "yes";
  283.    moveLayer.onEnterFrame = countdown;
  284.    moveLayer.hero.onEnterFrame = moveme;
  285. };
  286. intro.instructButton.onRelease = function()
  287. {
  288.    _root.gotoAndStop("instructions");
  289. };
  290. intro.playButton.onRollOver = function()
  291. {
  292.    this.gotoAndPlay("open");
  293. };
  294. intro.playButton.onRollOut = function()
  295. {
  296.    this.gotoAndPlay("close");
  297. };
  298. intro.instructButton.onRollOver = function()
  299. {
  300.    this.gotoAndPlay("open");
  301. };
  302. intro.instructButton.onRollOut = function()
  303. {
  304.    this.gotoAndPlay("close");
  305. };
  306.